package com.rentong.wx.cust.service.impl;

import com.rentong.wx.cust.dao.CustMessageChatTopDao;
import com.rentong.wx.cust.domain.CustMessageChatTopEntity;
import com.rentong.wx.cust.service.CustMessageChatTopService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;

@Service
public class CustMessageChatTopServiceImpl implements CustMessageChatTopService {

    @Resource
    private CustMessageChatTopDao custMessageChatTopDao;


    @Transactional(rollbackFor = Exception.class)
    @Override
    public Integer insertPinMessage(Long userId, Long custId) {
        CustMessageChatTopEntity custMessageChatTopEntity = new CustMessageChatTopEntity();

        try {
            custMessageChatTopEntity.setAddTime(new Date());
            custMessageChatTopEntity.setUpdateTime(new Date());
            custMessageChatTopEntity.setTopCustId(userId);
            custMessageChatTopEntity.setCustId(custId);
        } catch (Exception e) {
            e.printStackTrace();
        }

        if (custMessageChatTopDao.selectById(custId, userId) == 0) {
            return custMessageChatTopDao.insertSelective(custMessageChatTopEntity);
        }

        return 0;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Integer deleteCancelPinMessage(Long chatTopId) {
       return custMessageChatTopDao.deleteByPrimaryKey(chatTopId);
    }



}